
#include "MyFrameListener.h"


class Example1 : public ExampleApplication
{
public:
	Example1() { FrameListener = NULL; }
	~Example1() { 

		if(FrameListener) { delete FrameListener; }
	}

	void createScene() {
	
		Ogre::Plane plane(Vector3::UNIT_Y, -10);
		Ogre::MeshManager::getSingleton().createPlane("plane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 200, 200, true, 1, 5, 5, Vector3::UNIT_Z);
		Ogre::Entity* ent = mSceneMgr->createEntity("LightPlaneEntity", "plane");
		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
		ent->setMaterialName("Examples/BeachStones");

		Ogre::Light* light = mSceneMgr->createLight("Light1");
		light->setType(Ogre::Light::LT_DIRECTIONAL);
		light->setDirection(Ogre::Vector3(1,-1,0));
		
		Ogre::SceneNode* node = mSceneMgr->createSceneNode("node1");
		mSceneMgr->getRootSceneNode()->addChild(node);

		_SinbadEnt = mSceneMgr->createEntity("Sinbad","Sinbad.mesh");
		_SinbadNode = node->createChildSceneNode("SinbadNode");
		_SinbadNode->setScale(3.0f,3.0f,3.0f);
		_SinbadNode->setPosition(Ogre::Vector3(0.0f,4.0f,0.0f));
		_SinbadNode->attachObject(_SinbadEnt);

		Ogre::Entity* sword1 = mSceneMgr->createEntity("Sword1", "Sword.mesh");
		Ogre::Entity* sword2 = mSceneMgr->createEntity("Sword2", "Sword.mesh");
		_SinbadEnt->attachObjectToBone("Handle.L", sword1);
		_SinbadEnt->attachObjectToBone("Handle.R", sword2);


		mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);


		Ogre::AnimationStateSet* set = _SinbadEnt->getAllAnimationStates();
		Ogre::AnimationStateIterator iter = set->getAnimationStateIterator();

		while(iter.hasMoreElements()) {

			std::cout << iter.getNext()->getAnimationName() << std::endl;
		}
	}

	void createCamera() {

		mCamera = mSceneMgr->createCamera("MyCamera1");
		mCamera->setPosition(0,100,200);
		mCamera->lookAt(0,0,0);
		mCamera->setNearClipDistance(5);
	}
	/*
	void createViewports() {

		Ogre::Viewport* vp = mWindow->addViewport(mCamera);
		vp->setBackgroundColour(ColourValue(0.0f,0.0f,1.0f));
		mCamera->setAspectRatio(Real(vp->getActualWidth())/Real(vp->getActualHeight()));
	}*/

	void createFrameListener() {

		FrameListener = new MyFrameListener(_SinbadNode, _SinbadEnt, mWindow, mCamera);
		mRoot->addFrameListener(FrameListener);
	}

private:
	Ogre::SceneNode* _SinbadNode;
	Ogre::Entity* _SinbadEnt;
	Ogre::FrameListener* FrameListener;
};

int main(void) {

	Example1 app;
	app.go();

	return 0;
}